package com.astrofizzbizz.raspberrypicamera.client;

import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.logical.shared.SelectionEvent;
import com.google.gwt.event.logical.shared.SelectionHandler;
import com.google.gwt.user.client.ui.TabLayoutPanel;

public class MyTabLayoutPanel extends TabLayoutPanel
{
	private RaspberryPiCamera entryPoint;
	private CameraSettingsPanel cameraSettingsPanel;
	private TakeImagePanel takeImagePanel;
	private TimeLapseLatestImageViewerPanel timeLapseLatestImageViewerPanel;
	private int cameraSettingsPanelTabId;
	private int takeImagePanelTabId;
	private int timeLapseLatestImageViewerPanelTabId;
	
	public CameraSettingsPanel getCameraSettingsPanel() {return cameraSettingsPanel;}
	public TakeImagePanel getTakeImagePanel() {return takeImagePanel;}
	public TimeLapseLatestImageViewerPanel getTimeLapseLatestImageViewerPanel() {return timeLapseLatestImageViewerPanel;}

	public int getCameraSettingsPanelTabId() {return cameraSettingsPanelTabId;}
	public int getTakeImagePanelTabId() {return takeImagePanelTabId;}
	public int getTimeLapseLatestImageViewerPanelTabId() {return timeLapseLatestImageViewerPanelTabId;}
	
	public MyTabLayoutPanel(double barHeight, Unit barUnit, RaspberryPiCamera entryPoint) 
	{
		super(barHeight, barUnit);
		this.entryPoint = entryPoint;
		
		takeImagePanel = new TakeImagePanel(this.entryPoint);
	    add(takeImagePanel, "Single Image");
	    takeImagePanelTabId = 0;
	    
	    timeLapseLatestImageViewerPanel = new TimeLapseLatestImageViewerPanel(this.entryPoint);
	    add(timeLapseLatestImageViewerPanel, "Time Lapse");
	    timeLapseLatestImageViewerPanelTabId = 1;
	    	    
		cameraSettingsPanel = new CameraSettingsPanel(this.entryPoint);
	    add(cameraSettingsPanel, "Settings");
	    cameraSettingsPanelTabId = 2;
		
	    addSelectionHandler(new Se3TabLayoutPanelSelectionHandler(this));
	}
	public void showTab(int itab, boolean showTab)
	{
	    getTabWidget(itab).setVisible(showTab);
	    getTabWidget(itab).getParent().setVisible(showTab);
	}
	class Se3TabLayoutPanelSelectionHandler implements SelectionHandler<Integer>
	{
		MyTabLayoutPanel myTabLayoutPanel;
		Se3TabLayoutPanelSelectionHandler(MyTabLayoutPanel myTabLayoutPanel)
		{
			this.myTabLayoutPanel = myTabLayoutPanel;
		}
		@Override
		public void onSelection(SelectionEvent<Integer> event) 
		{
			  int tabId = event.getSelectedItem();
			  if (tabId == cameraSettingsPanelTabId) {}
			  if (tabId == takeImagePanelTabId) { }
			  if (tabId == timeLapseLatestImageViewerPanelTabId) 
			  {
				  timeLapseLatestImageViewerPanel.getGetLatestImageTimer().setPause(false);
			  }
			  else
			  {
				  timeLapseLatestImageViewerPanel.getGetLatestImageTimer().setPause(true);
			  }
		}
		
	}

}
